/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-use-before-define */
/* eslint-disable @typescript-eslint/no-use-before-define */
import React, { Fragment } from 'react';
import { Link } from 'dva/router';
import DocumentTitle from 'react-document-title';
import { Icon } from 'antd';
import GlobalFooter from '@/components/GlobalFooter';
import { connect } from 'dva';
import styles from './UserLayout.less';

const links = [
  {
    key: 'help',
    title: '帮助',
    href: '',
  },
  {
    key: 'privacy',
    title: '隐私',
    href: '',
  },
  {
    key: 'terms',
    title: '条款',
    href: '',
  },
];

@connect(({ setting }) => ({
  ...setting,
}))
class UserLayout extends React.PureComponent {
  getPageTitle() {
    const {
      options: { key, subKey },
    } = this.props;
    const titleMap = {
      yz: '快宝智慧快递管理平台-快递末端企业专用管理系统',
      post: '中邮共配管理系统',
      yjy: '驿加易共配管理系统',
      td: '智慧快递管理平台',
    };
    return titleMap[subKey || key];
  }

  render() {
    const { children, options } = this.props;
    const { recordNo, copyright, name, logo, key, showAdv } = options;
    const isKbCity = key === 'yz' && showAdv;

    const year = new Date().getFullYear();
    return (
      <DocumentTitle title={this.getPageTitle()}>
        <div className={styles[isKbCity ? 'kbcontainer' : 'container']}>
          <div className={styles[isKbCity ? 'kbcontent' : 'content']}>
            {!isKbCity && (
              <div className={styles.top}>
                {key != 'yz' && (
                  <div className={styles.header}>
                    <Link to="/">
                      <img alt="logo" className={styles.logo} src={logo} />
                      <span className={styles.title}>{name}</span>
                    </Link>
                  </div>
                )}
                <div className={styles.desc} />
              </div>
            )}
            {children}
          </div>
          <GlobalFooter
            links={links}
            copyright={
              <Fragment>
                Copyright <Icon type="copyright" /> {year} {copyright}
              </Fragment>
            }
            recordNo={recordNo}
          />
        </div>
      </DocumentTitle>
    );
  }
}

export default UserLayout;
